package com.lagou.homework.service.impl;

import com.lagou.homework.service.EmailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

@Service
public class EmailServiceImpl implements EmailService {

    @Autowired
    private JavaMailSender javaMailSender;

    @Override
    public boolean sendEmail(String email,String code) {
        try {
            SimpleMailMessage msg = new SimpleMailMessage();
            msg.setFrom("280740733@qq.com");//发送者
            msg.setTo(email);//接收者
            msg.setSubject("注册验证码");//标题
            msg.setText(code);//内容
            javaMailSender.send(msg);
            return true;
        }catch (Exception e){
            return false;
        }
    }
}
